Crate alloy_primitives

source ·
Expand description

alloy-primitives

Primitive types shared by alloy, foundry, revm, and reth.

Types

  • Unsigned integers re-exported from ruint
  • Signed integers, as a wrapper around ruint integers
  • Fixed-size byte arrays via FixedBytes
    • a macro wrap_fixed_bytes for constructing named fixed bytes types
    • Address, which is a fixed-size byte array of 20 bytes, with EIP-55 and EIP-1191 checksum support

Examples

This library has straightforward, basic, types. Usage is correspondingly simple. Please consult the documentation for more information.

use alloy_primitives::{U256, Address, FixedBytes, I256};

// FixedBytes
let n: FixedBytes<6> = "0x1234567890ab".parse().unwrap();
assert_eq!(n.to_string(), "0x1234567890ab");

// Uint
let mut n: U256 = "42".parse().unwrap();
n += U256::from(10);
assert_eq!(n.to_string(), "52");

// Signed
let mut n: I256 = "-42".parse().unwrap();
n = -n;
assert_eq!(n.to_string(), "42");

// Address
let addr_str = "0x66f9664f97F2b50F62D13eA064982f936dE76657";
let addr: Address = Address::parse_checksummed(addr_str, None).unwrap();
assert_eq!(addr.to_checksum(None), addr_str);

// Address with custom chain id
let addr_str = "0x66F9664f97f2B50F62d13EA064982F936de76657";
let addr: Address = Address::parse_checksummed(addr_str, Some(30)).unwrap();
assert_eq!(addr.to_checksum(Some(30)), addr_str);

Re-exports

Modules

  • Type aliases for common primitive types.

Macros

Structs

  • An Ethereum address, 20 bytes in length.
  • The error type that is returned when conversion to or from a integer fails.
  • Ethereum 256 byte bloom filter.
  • Wrapper type around Bytes to deserialize/serialize “0x” prefixed ethereum hex strings.
  • A byte array of fixed length ([u8; N]).
  • Signed integer wrapping a ruint::Uint.

Enums

Constants

Functions

Type Definitions

  • 8-byte fixed array type.
  • 16-byte fixed array type.
  • 32-byte fixed array type.
  • 64-byte fixed array type.